package flc.ast.adapter;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyLocalAlbumBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.view.container.StkRecycleView;

public class LocalAlbumAdapter extends StkProviderMultiAdapter<MyLocalAlbumBean> {

    public LocalAlbumAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(125));
        addItemProvider(new LocalAlbumProvider());
    }

    private boolean isEdit = false;

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class LocalAlbumProvider extends BaseItemProvider<MyLocalAlbumBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_local_album;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyLocalAlbumBean bean) {
            baseViewHolder.setText(R.id.tvLocalAlbumItemDate, bean.getDate() + "  (" + bean.getList().size() + ")");
            StkRecycleView recycleView = baseViewHolder.getView(R.id.rvLocalAlbumItemList);
            recycleView.setLayoutManager(new GridLayoutManager(getContext(), 3));
            LocalAlbumItemAdapter itemAdapter = new LocalAlbumItemAdapter();
            recycleView.setAdapter(itemAdapter);
            itemAdapter.setEdit(isEdit);
            itemAdapter.setList(bean.getList());
            itemAdapter.setOnItemClickListener(getOnItemClickListener());
        }
    }

}
